﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;

namespace FDeal
{
    public class DiaDiemDealDAO : DataProvider
    {
        public DiaDiemDealDAO()
        { 
        }

        public DiaDiemDealDTO[] getDsDiaDiemDeal()
        {
            connect();
            string query = "SELECT * FROM DIADIEMDEAL";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            DiaDiemDealDTO[] arr;

            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            arr = new DiaDiemDealDTO[n];
            for (i = 0; i < n; i++)
            {
                object lop = GetDataFromDataRow(dt, i);
                arr[i] = (DiaDiemDealDTO)lop;
            }
            return arr;
        }



        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            DiaDiemDealDTO ddd = new DiaDiemDealDTO();
            ddd.Iddiadiem = dt.Rows[i]["IDDIADIEM"].ToString();
            ddd.Diachi = dt.Rows[i]["DIACHI"].ToString();
            ddd.Tinh = dt.Rows[i]["TINH"].ToString();

            return (object)ddd;
        }

        public void insert(DiaDiemDealDTO info)
        {
            string insertCommand = "INSERT INTO DIADIEMDEAL VALUES ('" +
                info.Iddiadiem + "','" +
                info.Diachi + "','" +

                info.Tinh + "')";

            executeNonQuery(insertCommand);
        }

        public void update(DiaDiemDealDTO info)
        {
            string updateCommand = "UPDATE DIADIEMDEAL " +
                                    "SET DIACHI = '" + info.Diachi + "', " +
                                    " TINH = '" + info.Tinh + "'," +

                                    " WHERE IDDIADIEM  = '" + info.Iddiadiem + "'";

            executeNonQuery(updateCommand);
        }

        public void delete(string idtendd)
        {
            string deleteCommand = "DELETE FROM DIADIEMDEAL WHERE IDDIADIEM = '" + idtendd + "'";
            executeNonQuery(deleteCommand);
        }
    }
}